package com.tom.basic.service.impl;

import com.tom.basic.mapper.BaseMapper;

import com.tom.basic.query.BaseQuery;
import com.tom.basic.service.IBaseService;
import com.tom.basic.utils.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;


@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }
    @Transactional
    @Override
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Transactional
    @Override
    public void save(T t) {
        baseMapper.save(t);

    }
    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        // 查询当前页数据
        List<T> rows = baseMapper.queryData(baseQuery);

        // 查询总条数
        Integer total = baseMapper.queryCount(baseQuery);

        return new PageList<>(total,rows);
    }
    @Transactional
    @Override
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }


}
